/*
 * @Description: 
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2021-04-21 14:07:44
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-21 17:12:05
 */
class Watcher {
    constructor(vm, key, cb) {
        this.vm = vm
        this.key = key
        this.cb = cb
        // this.vm[key]会触发该属性的getter 方法
        Dep.target = this
        this.oldValue = this.vm[key]
        Dep.target = null
    }
    update() {
        if (this.oldValue === this.vm[this.key]) {
            return
        }
        // 更新视图
        this.cb(this.vm[this.key])
    }
}